<?php
/*------------------------------------------------------------------------------
this file is part of Web Application Kit http://webappkit.net
Copyright (C) 2006 J.Ducastel <fredbird@fredbird.org>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
------------------------------------------------------------------------------*/

/**
*
* @author J.Ducastel <fredbird@fredbird.org>
* @version 
*/
class wakTriggerStore_ini extends wakTriggerStore {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access
	*/
	function wakTriggerStore_ini($file) {
		$this->__construct($file);
	}/**/
	
	/**
	* "real" constructor
	* @access
	*/
	function __construct($file) {
		$lib=wak::getservice('waklib');
		$lib->needclass('databeanstore_ini');
		$lib->needclass('waktrigger');
		$this->store=&new databeanstore_ini($file);
		$this->store->setclass('waktrigger');
		$this->triggers=$this->store->getall();
	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* return request-applying waktrigger instances
	* sorted by priority down
	* @param wakHttpRequest $req
	* @access public
	* @return array 
	*/
	function getRequestTriggers($req) {
		$match=array(); $n=999;
		foreach ($this->triggers as $trigger) {
			if ($trigger->matchRequest($req)) {
				$key=sprintf('%03d',$trigger->get('priority')).'-'.$n;
				$match[$key]=$trigger;
				$n--;
			}
		}
		krsort($match);
		return $match;
	}/**/
	
	/**
	* imports request-applying triggers into wak triggers pile service
	* @param wakHttpRequest $req
	* @access public
	* @return bool
	*/
	function requestTriggersToPile($req) {
		$pile=&wak::getservice('waktriggerspile');
		foreach ($this->triggers as $trigger) {
			if ($trigger->matchRequest($req)) {
				$pile->addTrigger($trigger);
			}
		}
		return true;
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var type desc
	*/
	var $file; // storage file
	var $store; // wakdatabeanstore instance
	var $triggers; // all triggers instances
/*------------------------------------------------------------------------------
                                                               protected methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access protected
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access protected
	* @return 
	* /
	function () {
		
	}/**/
	
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
}
?>
